/*
 * Copyright (C) 2004, Velocityme Partnership
 * ContactableActions.java
 *
 * Created on 28 September 2004, 07:45
 */

package com.velocityme.www.interfaces.nodeactions;

import com.velocityme.interfaces.*;
import com.velocityme.utility.InvalidKeyException;
import com.velocityme.valueobjects.ContactDetailTypeValue;
import com.velocityme.valueobjects.ContactDetailValue;
import com.velocityme.valueobjects.ContactableValue;
import com.velocityme.www.actionforms.nodeactionforms.ContactableValueActionForm;
import java.rmi.RemoteException;
import java.text.DecimalFormat;
import java.util.Iterator;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.actions.DispatchAction;

/**
 *
 * @author  Robert
 */
public class ContactableActions extends NodeActions {
    
    DecimalFormat m_decimalFormat = new DecimalFormat("000");

    /** Creates a new instance of ContactableActions */
    public ContactableActions() {
    }
    
    protected void createContactDetails(KeySession p_key,
                                        RemoteClientSession p_cs,
                                        ContactableValueActionForm p_contactableValueActionForm) throws InvalidKeyException, RemoteException {
        p_contactableValueActionForm.setContactDetailTypeValues(p_cs.getAllContactDetailValues(p_key));
    }
    
    protected void editContactDetails(KeySession p_key,
                                      RemoteClientSession p_cs,
                                      ContactableValue p_contactableValue,
                                      ContactableValueActionForm p_contactableValueActionForm) throws InvalidKeyException, RemoteException {
        p_contactableValueActionForm.setContactDetailTypeValues(p_cs.getAllContactDetailValues(p_key));
        ContactDetailValue[] contactDetailValues = p_contactableValue.getContactDetailValues();
        for (int j = 0; j < contactDetailValues.length; j++) {
            String key = m_decimalFormat.format(contactDetailValues[j].getContactDetailTypeValue().getSequenceNumber().intValue());
            p_contactableValueActionForm.setContactDetailValue(key, contactDetailValues[j].getValue());
            p_contactableValueActionForm.setContactDetailId(key, contactDetailValues[j].getContactDetailId());
        }
    }
    
}
